package study05;

import java.io.*;

public class Java06_Copy_stringfy_parse {
    public static void main(String[] args) throws Exception {
//        序列化和繙序列化
//        数据源文件
        File dataFile = new File("D:\\java_study\\java_study\\data\\obj.dat");

        //    對象输出流
        ObjectOutputStream objectOut = null;
        FileOutputStream out = null;

//            反序列化变成对象  对象输入流
        ObjectInputStream objectIn = null;
        FileInputStream in = null;

        try {
//            out = new FileOutputStream(dataFile);
//            objectOut = new ObjectOutputStream(out);
//
////            Java 中只有增加了特殊的标记的类，才能在写文件时做序列化操作
//            User user = new User();
//            objectOut.writeObject(user);
//            objectOut.flush();

//            从文件中读取数据转化为对象
            in = new FileInputStream(dataFile);
            objectIn = new ObjectInputStream(in);
            Object o = objectIn.readObject();
            System.out.println(o);

        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (objectOut != null) {
                try {
                    objectOut.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}

//Serializable 自动序列化
class User implements Serializable {

}
